package net.app.zoneland.platform.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.app.zoneland.domain.SysUser;
import net.app.zoneland.vo.UserVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Description
 * @Author LENOVO
 * @CreateTime 2020/12/20 12:44
 * @Version: 1.0
 */
@Mapper
public interface SysUserMapper extends BaseMapper<SysUser> {

    /**
     * 查询用户信息分页
     * @param page
     * @param user
     * @return
     */
    @Select("<script> " +
            "   select u.* from sys_user u " +
            "   where deleted=0 " +
            " <if test ='user.nickname!=null and user.nickname.trim() neq \"\"'>" +
            "       and u.nickname like concat('%',#{user.nickname},'%')" +
            " </if>" +
            " <if test ='user.mobile!=null and user.mobile.trim() neq \"\"'>" +
            "       and u.mobile like concat('%',#{user.mobile},'%')" +
            " </if>" +
            " <if test ='user.status!=null'>" +
            "       and u.status = #{user.status}" +
            " </if>" +
            "</script>")
    List<SysUser> list(Page<SysUser> page, SysUser user);

    List<SysUser> queryUserPage(Page<SysUser> page, SysUser user);

    UserVo queryUserInfoByUserName(String username);

    void updateStatusById(@Param("user")SysUser user);

    void saveSysUserCallId(@Param("user")SysUser user);

    @Update("<script> "+
          "update sys_user set "+
          "password=#{user.password} " +
          "where username=#{user.username} " +
          "</script>"
    )
    void changpwd(@Param("user")SysUser user);

    @Update("<script>"+
            " update sys_user "+
            " <trim prefix=\"set\" suffixOverrides=\",\">" +
            " <if test=\"user.nickname!=null\"> nickname=#{user.nickname}, </if>" +
            " <if test=\"user.mobile!=null\"> mobile=#{user.mobile}, </if>" +
            " <if test=\"user.description!=null\"> description=#{user.description}, </if>" +
            " <if test=\"user.addr!=null\"> addr=#{user.addr}, </if>" +
            " <if test=\"user.email!=null\"> email=#{user.email}, </if>" +
            " <if test=\"user.avatar!=null\"> avatar=#{user.avatar}, </if>" +
            " </trim>"+
            " where username=#{user.username} " +
            "</script>"
    )
    void updateUser(@Param("user")UserVo user);
}
